package com.example.qincetest.ui.activity

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Button
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.example.qincetest.network.OkHttpConfig

class NetworkActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            MaterialTheme {
                Surface(
                    modifier = Modifier.fillMaxSize(),
                    color = MaterialTheme.colorScheme.background
                ) {
                    NetworkScreen()
                }
            }
        }
    }
}

@Composable
fun NetworkScreen() {
    Column(
        modifier = Modifier
            .fillMaxSize()
            .padding(16.dp)
    ) {
        Button(
            onClick = {
                OkHttpConfig.getBaiduApiForceNetwork()
            }
        ) {
            Text("强制从网络获取")
        }
        
        Button(
            onClick = {
                OkHttpConfig.getBaiduApi()
            },
            modifier = Modifier.padding(top = 8.dp)
        ) {
            Text("尝试从缓存获取")
        }

        Button(
            onClick = {
                OkHttpConfig.clearCache()
            },
            modifier = Modifier.padding(top = 8.dp)
        ) {
            Text("清空缓存")
        }
    }
}